import { createRouter, createWebHistory } from 'vue-router'

// 路由配置
const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/workbenches/index'),
    meta: {
      title: '主应用首页'
    }
  },
  {
    path: '/exp/:catchAll(.*)*',
    name: 'SubApp',
    component: () => import('@/views/workbenches/subApp'),
    meta: {
      title: '子应用'
    }
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('@/views/workbenches/about'),
    meta: {
      title: '关于'
    }
  },
  {
    path: '/:pathMatch(.*)*',
    name: '404',
    component: () => import('@/views/error/404'),
    meta: {
      title: '404'
    }
  }
]

// 创建路由实例
const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  console.log('[主应用] 路由跳转:', to.path)
  // 设置页面标题
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router 